package com.qdhhxy.service;

import com.qdhhxy.entity.CarEntity;
import com.qdhhxy.entity.UserEntity;
import com.qdhhxy.mapper.CarMapper;
import com.qdhhxy.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class Carservice implements ICarservice {
    @Autowired
    private CarMapper carMapper;
    @Autowired
    private UserMapper userMapper;



    @Override
    public String insertCar(CarEntity carEntity){
        System.out.println("service");
        carMapper.insertCar(carEntity);
        return "insert car";
    }

    @Override
    public CarEntity selectCarById(int id) {
        CarEntity car = carMapper.selectCarById(id);
        int stuId = car.getStuId();
        UserEntity user = userMapper.selectUserById(stuId);
        car.setUserEntity(user); // 设置 userEntity
        return car;
    }
    public List<CarEntity> selectCarByStuId(int stuId) {
        List<CarEntity> cars = carMapper.selectCarByStuId(stuId);
        return cars;
    }
}
